package XynLeen.GraduationProject.Activities;

import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.constraint.ConstraintLayout;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

import XynLeen.GraduationProject.R;
import butterknife.Bind;
import butterknife.ButterKnife;

import static com.youth.xframe.utils.XBitmapUtils.getBitmapFromView;

public class Activity_Invitation_Five extends AppCompatActivity implements View.OnClickListener {
    @Bind(R.id.ib_navigation_back)
    ImageButton mIbNavigation_back;
    @Bind(R.id.ib_navigation_share)
    ImageButton mIbNavigation_share;
    @Bind(R.id.tv_navigation_label)
    TextView mTvNavigation;
    @Bind(R.id.conslayout)
    ConstraintLayout clayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_invitation_five);

        ButterKnife.bind(this);

        mTvNavigation.setText("查看请帖");
        mIbNavigation_share.setOnClickListener(this);
        mIbNavigation_back.setOnClickListener(this);
    }

    @Override
    public void onBackPressed() {
        Intent intent = new Intent(this, Activity_Invitation.class);
        startActivity(intent);
        finish();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.ib_navigation_share:
                Bitmap bitmap=getBitmapFromView(clayout);
                MediaStore.Images.Media.insertImage(getContentResolver(), bitmap, "title", "description");
                Toast.makeText(this, "请帖已保存到相册，快去分享给朋友吧！", Toast.LENGTH_SHORT).show();
                break;
            case R.id.ib_navigation_back:
                Intent intent = new Intent(this, Activity_Invitation.class);
                startActivity(intent);
                finish();
                break;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ButterKnife.unbind(this);
    }
}
